package com.flame.user.message.controller;

import java.util.List;

import com.flame.core.protocol.PageResult;
import com.flame.core.protocol.Result;
import com.flame.user.message.controller.vo.UserMessageVo;
import com.flame.user.message.entity.UserMessage;
import com.flame.user.message.service.UserMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * flame_user_message 用户消息表
 *
 * @author 吴欣童
 * @since 2023-02-14 20:28:48
 */
@RestController
public class UserMessageController {

    @Autowired
    private UserMessageService userMessageService;
    
    @PostMapping("/user/message/page")
    public PageResult pageUserMessage(@RequestBody UserMessageVo userMessageVo) {
        return PageResult.success(userMessageService.pageUserMessage(userMessageVo));
    }

    @PostMapping("/user/message/count")
    public Result countUserMessageByStatus(@RequestBody UserMessage userMessage){
        return Result.success(userMessageService.countUserMessageByStatus(userMessage));
    }

    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/user/message/add")
    public Result addUserMessage(@RequestBody @Validated UserMessage userMessage) {
        userMessageService.addUserMessage(userMessage);
        return Result.success();
    }

    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/user/message/complete")
    public Result completeUserMessage(@RequestBody @Validated List<UserMessage> userMessageList) {
        userMessageService.completeUserMessage(userMessageList);
        return Result.success();
    }

    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/user/message/delete")
    public Result deleteUserMessage(@RequestBody @Validated UserMessage userMessage) {
        userMessageService.deleteUserMessage(userMessage);
        return Result.success();
    }
}
